{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true,
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# 使用Sklearn实现Ridge、LASSO和Elastic Net"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn import linear_model"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 加载数据的函数"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [],
   "source": [
    "def loaddata():\n",
    "    data = np.loadtxt('data/data1.txt',delimiter=',')\n",
    "    n = data.shape[1]-1 #特征数\n",
    "    X = data[:,0:n]\n",
    "    y = data[:,-1].reshape(-1,1)\n",
    "    return X,y"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "source": [
    "X,y = loaddata()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "execution_count": 12,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 1、线性回归(最小二乘实现)\n",
    "linear_model中的LinearRegression()方法可以实现线性回归"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "outputs": [],
   "source": [
    "model1 = linear_model.LinearRegression()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "fit()方法可以加载训练数据并进行训练"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "outputs": [
    {
     "data": {
      "text/plain": "LinearRegression()"
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#调用fit方法\n",
    "model1.fit(X,y)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "intercept_属性可以输出$\\theta_0$的值，coef_属性可以输出$\\theta_1$到$\\theta_n$的值"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1.19303364]]\n",
      "[-3.89578088]\n"
     ]
    }
   ],
   "source": [
    "print(model1.coef_)\n",
    "print(model1.intercept_)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "outputs": [
    {
     "data": {
      "text/plain": "[<matplotlib.lines.Line2D at 0x1bce8b43cd0>]"
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": "<Figure size 432x288 with 1 Axes>",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXIAAAD5CAYAAAA6JL6mAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAgN0lEQVR4nO3de3xU5Z0/8M83MWjACyKokJIGb2FVVtCU2tIqYFsQbKX0VS/bi7vtlrpb20Vt2oC2YrWSlqq13d126cqvWi+LrZCyggIKFrULbbiJCHjBQBkQghhUiJDL9/fHzMTJnHNmzsycy3NmPu/Xy1eSZ25fJsdPnnnO8zxHVBVERBRdZWEXQEREhWGQExFFHIOciCjiGORERBHHICciijgGORFRxB2T7Q4iMhTAgwBOB9ANYK6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8XwBYAVTD0OHaq189j2MQgVwDLRGStiEyzub0KwN9Sft6VaAvbNXA++D8mIhtF5EkROS/Iohycpqp7gPhBB+BUm/uY+j4DwNcQ/1RmJ9vxE6QbEh+j5zl87DfxPf4kgL2q+qrD7aG+vyJSA2AUgDWIwHGcVm8qT49hEy8sMUZVd4vIqQCWi8jWRA8iSWweE+rUGxHpA+BzAGbY3LwO8eGW9xLjpE0Azg6wvHwZ9z4DgIjcAqATwMMOd8l2/ATlVwDuQPw9uwPx4Yqvpd3HxPf4WmTujYf2/orI8QAeBzBdVd+Jf3jI/jCbtkDe4/R6U9o9P4aN65Gr6u7E130AFiL+0SjVLgBDU37+EIDdwVTn6HIA61R1b/oNqvqOqr6X+H4JgAoRGRh0gWn2JoejEl/32dzHuPdZRK4DcAWAL2liMDGdi+MnEKq6V1W7VLUbwG8c6jDqPRaRYwBMBTDf6T5hvb8iUoF4KD6sqgsSzcYexw71+nYMGxXkItJPRE5Ifo/4yYGX0u62CMBXJe5iAAeTH69C5NiLEZHTE+OOEJHRiL/nbwVYm51FAK5LfH8dgD/a3OevAM4WkWGJTxzXJB4XChGZCOD7AD6nqocd7uPm+AlE2nmbzzvUYdR7DOBTALaq6i67G8N6fxP//9wPYIuq3pNyk5HHsVO9vh7Dfp69zeNs7xmIn1XeCGAzgFsS7dcDuD7xvQD4D8TPRG8CUBdyzX0RD+aTUtpS670h8W/ZiPgJjo8HXN+jAPYA6EC8d/J1AKcAeAbAq4mvAxL3HQJgScpjJyF+xv315O8ixJpfQ3ysc0Piv1+n1+x0/IRU7+8Sx+eLiAfHYFPeY7t6E+2/TR63Kfc14f39BOLDIS+m/P4nmXocZ6jXt2OYKzuJiCLOqKEVIiLKHYOciCjiGORERBHHICciijgGORFRxDHIiYgijkFORBRxDHIiooj7/32RN7MpLVE/AAAAAElFTkSuQmCC\n"
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(X,y)\n",
    "y_hat = model1.predict(X)\n",
    "plt.plot(X,y_hat)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 2、Ridge\n",
    "linear_model中的Ridge方法可以实现Ridge回归\n",
    "\n",
    "注意：这里的alpha表示正则化强度\n",
    "\n",
    "normalize设置为True表示对训练数据进行标准化"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1.19302535]]\n",
      "[-3.89571317]\n"
     ]
    },
    {
     "data": {
      "text/plain": "[<matplotlib.lines.Line2D at 0x1bce8c653a0>]"
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": "<Figure size 432x288 with 1 Axes>",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXIAAAD5CAYAAAA6JL6mAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAgJ0lEQVR4nO3dfXhU1Z0H8O8vMWrEF0BQMYKhaqEoLWhKu0Vd0NYg2Ir2qdXti7t2S9tdu2Jt1qC1Yn0hLVXXdnfr0tVWLavYivEFFChgqbboBgICC4hgoAwUUIwiRAnJb/+YuXEy996ZOzP35dyZ7+d5fAhn3n5Mrt85c+4554qqgoiI4qsi6gKIiKg4DHIiophjkBMRxRyDnIgo5hjkREQxxyAnIoq5w3LdQUQGA3gYwEkAugHMUtX7RGQ6gG8C2JO6602qOj/bcw0YMEBra2uLKpiIqNysWLHiTVUd6HZ7ziAHcAjADaq6UkSOAbBCRBalbrtXVX/qtZja2lq0tLR4vTsREQEQka3Zbs8Z5Kq6E8DO1M/7RGQ9gBp/yiMiomLlNUYu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AXaq6yeX2SN9fEakFMBrAy4jBcZxRbzpfj2ETLywxVlV3iMgJABaJyIZUD8IiDo+JdOqNiBwO4AsApjncvBLJ4Zb3UuOkzQDOCLG8Qhn3PgOAiNwM4BCA2S53yXX8hOUXAG5H8j27Hcnhimsy7mPie3wVsvfGI3t/ReRoAE8AmKqq7ya/POR+mENbKO9xZr1p7b4fw8b1yFV1R+rP3QCeRPKrUbrtAAan/f0UADvCqc7VxQBWququzBtU9V1VfS/183wAVSIyIOwCM+yyhqNSf+52uI9x77OIXA3gEgBf0dRgYiYPx08oVHWXqnapajeAX7rUYdR7LCKHAbgcwBy3+0T1/opIFZKhOFtV56aajT2OXeoN7Bg2KshFpI+IHGP9jOTJgbUZd3sawNcl6dMA3rG+XkXItRcjIielxh0hImOQfM/fCrE2J08DuDr189UAnnK4z/8COENEhqa+cVyZelwkRGQCgBsBfEFVD7jcx8vxE4qM8zaXudRh1HsM4LMANqjqdqcbo3p/U///PABgvarek3aTkcexW72BHsNBnr0t4GzvR5A8q7wawDoAN6favw3g26mfBcB/IHkmeg2AuohrPgrJYD4urS293mtT/5bVSJ7g+EzI9T0KYCeATiR7J98AcDyAxQA2pf7sn7rvyQDmpz12IpJn3Ddbv4sIa34dybHOVan/7s+s2e34iajeR1LH56tIBscgU95jp3pT7b+2jtu0+5rw/p6L5HDIq2m//4mmHsdZ6g3sGObKTiKimDNqaIWIiPLHICciijkGORFRzDHIiYhijkFORBRzDHIiophjkBMRxRyDnIgo5v4f4L03rxjhLNUAAAAASUVORK5CYII=\n"
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "model2 = linear_model.Ridge(alpha=0.01)\n",
    "model2.fit(X,y)\n",
    "print(model2.coef_)\n",
    "print(model2.intercept_)\n",
    "plt.scatter(X,y)\n",
    "y_hat = model2.predict(X)\n",
    "plt.plot(X,y_hat)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 3、LASSO\n",
    "linear_model中Lasso()方法可以实现Lasso回归\n",
    "\n",
    "注意：这里的alpha表示正则化强度\n",
    "\n",
    "normalize设置为True表示对训练数据进行标准化"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1.19235895]\n",
      "[-3.89027554]\n"
     ]
    },
    {
     "data": {
      "text/plain": "[<matplotlib.lines.Line2D at 0x1bce8ccff40>]"
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": "<Figure size 432x288 with 1 Axes>",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXIAAAD5CAYAAAA6JL6mAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAgUUlEQVR4nO3dfXxU1Z0/8M83MdqIrhEBhQgGHxarpZCaIhXrgtpiwSrS1ZZ2q13dTbut/srWzc+AraJtJV1au7rd1lKlamstPmDUgkWKuLRUoIGAiICIBMqAGIUolSgh+e4fMxMnc++duTNzH86d+bxfL1+EMw/3y2T8zJlzzzlXVBVERBRdZWEXQEREhWGQExFFHIOciCjiGORERBHHICciijgGORFRxB2R7Q4iMhTAgwBOAtADYK6q3iUiswD8K4D2xF1nquqiTM81YMAArampKahgIqJSs2bNmjdVdaDT7VmDHMBhADeq6loRORbAGhFZkrjtx6r6Q7fF1NTUoKWlxe3diYgIgIjsyHR71iBX1T0A9iR+PiAimwBUe1MeEREVKqcxchGpAVALYFWi6XoReVFE5onI8V4XR0RE2bkOchE5BsDjAKar6jsAfgbgNACjEe+x/8jhcfUi0iIiLe3t7XZ3ISKiArgKchGpQDzEH1LVBQCgqntVtVtVewD8AsAYu8eq6lxVrVPVuoEDHc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qjYgcCeAyADNsbl6L+HDL3xLjpM0AzgiwvHwZ9zoDgIjcDOAwgIcc7pLt/ROUnwH4LuKv2XcRH664Nu0+Jr7G05C5Nx7a6ysixwB4HMB0VX0n/uUh+8Ns2gJ5jdPrTWn3/D1sXI9cVXcn/nwDwBOIfzVKtQvA0JS/nwxgdzDVOfoMgLWqujf9BlV9R1X/lvh5EYAKERkQdIFp9iaHoxJ/vmFzH+NeZxG5BsClAL6kicHEdC7eP4FQ1b2q2q2qPQB+4VCHUa+xiBwBYCqA+U73Cev1FZEKxEPxIVVdkGg29n3sUK9v72GjglxE+onIscmfET858FLa3Z4CcLXEjQXwdvLrVYgcezEiclJi3BEiMgbx1/ytAGuz8xSAaxI/XwPgSZv7/AXAGSIyPPGN4wuJx4VCRC4BcBOAy1T1oMN93Lx/ApF23uYKhzqMeo0BXAxgs6rusrsxrNc38f/PfQA2qeqdKTcZ+T52qtfX97CfZ2/zONt7KuJnldcD2Ajg5kT71wB8LfGzAPgfxM9EbwBQF3LNRyMezMeltKXWe33i37Ie8RMc5wVc38MA9gDoQrx3ch2AEwAsBbA18Wf/xH2HAFiU8thJiJ9x35b8XYRY86uIj3WuS/x3T3rNTu+fkOr9VeL9+SLiwTHYlNfYrt5E+/3J923KfU14fc9HfDjkxZTf/yRT38cZ6vXtPcyVnUREEWfU0AoREeWOQU5EFHEMciKiiGOQExFFHIOciCjiGORERBHHICciijgGORFRxP0fzzk6wEXymDMAAAAASUVORK5CYII=\n"
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "model3 = linear_model.Lasso(alpha=0.01)\n",
    "model3.fit(X,y)\n",
    "print(model3.coef_)\n",
    "print(model3.intercept_)\n",
    "plt.scatter(X,y)\n",
    "y_hat = model3.predict(X)\n",
    "plt.plot(X,y_hat)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 4、ElactisNet\n",
    "linear_model中的ElasticNet()方法可以实现弹性网\n",
    "\n",
    "注意：这里的alpha表示正则化强度\n",
    "\n",
    "normalize设置为True表示对训练数据进行标准化"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1.19229408]\n",
      "[-3.88974622]\n"
     ]
    },
    {
     "data": {
      "text/plain": "[<matplotlib.lines.Line2D at 0x1bce8d4e520>]"
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": "<Figure size 432x288 with 1 Axes>",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXIAAAD5CAYAAAA6JL6mAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAgW0lEQVR4nO3de3hU1bk/8O+bGDSgR0BQIIIB7QlVUYGoKNqK9hQET6X0p62XHlvbcjynnlNaT9qgrdKqJS3VtudXq8Vq1dYLbblIBUUqtFYUNJBwU1CRiw6IUQwqRAnJe/6YmTiZvffMnpl9WXvm+3keH8Kay36ZjN9Zs/Zaa4uqgoiIoqss7AKIiKgwDHIioohjkBMRRRyDnIgo4hjkREQRxyAnIoq4Q7LdQUQGA3gAwAAAnQBmq+ovRWQGgG8AaEnc9XpVXZzpufr166fV1dUFFUxEVGpWr179tqr2d7o9a5ADOAjgOlVdIyJHAFgtIksTt/1cVX/mtpjq6mo0Nja6vTsREQEQke2Zbs8a5Kq6C8CuxM/vi8hLAKq8KY+IiAqV0xi5iFQDGAlgVaLpWhFZJyL3ikgfr4sjIqLsXAe5iBwOYC6Aaar6HoA7ARwP4DTEe+y3OTxuqog0ikhjS0uL3V2IiKgAroJcRCoQD/EHVXUeAKjqblXtUNVOAHcDOMPusao6W1VrVbW2f3/HsXoiI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e5eQ3iwy0fJMZJFwD4RIDl5cu41xkAROQGAAcBPOhwl2zvn6DcCeBmxF+zmxEfrrg67T4mvsaXIXNvPLTXV0QOBzAXwDRVfS/+5SH7w2zaAnmN0+tNaff8PWxcj1xVdyb+fAvAfMS/GqV6A8DglL8fC2BnMNU5uhDAGlXdnX6Dqr6nqh8kfl4MoEJE+gVdYJrdyeGoxJ9v2dzHuNdZRK4CcBGAKzQxmJjOxfsnEKq6W1U7VLUTwN0OdRj1GovIIQCmAJjjdJ+wXl8RqUA8FB9U1XmJZmPfxw71+vYeNirIRaSXiByR/BnxkwMb0u62EMC/SdwYAHuTX69C5NiLEZEBiXFHiMgZiL/m7wRYm52FAK5K/HwVgEdt7vMCgE+IyNDEN44vJR4XChGZAOB7AD6nqvsd7uPm/ROItPM2n3eow6jXGMBnAGxS1Tfsbgzr9U38/3MPgJdU9faUm4x8HzvV6+t72M+zt3mc7R2G+FnltQA2Argh0X4NgGsSPwuAOxA/E70eQG3INfdEPJiPTGlLrffaxL9lLeInOM4OuL6HAewC0I547+RrAI4C8BSAVxJ/9k3cdxCAxSmPnYj4Gfctyd9FiDW/ivhYZ3Piv7vSa3Z6/4RU7+8T7891iAfHQFNeY7t6E+33Jd+3Kfc14fU9B/HhkHUpv/+Jpr6PM9Tr23uYKzuJiCLOqKEVIiLKHYOciCjiGORERBHHICciijgGORFRxDHIiYgijkFORBRxDHIiooj7P84HN7+q7xjdAAAAAElFTkSuQmCC\n"
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "model4 = linear_model.ElasticNet(alpha=0.01)\n",
    "model4.fit(X,y)\n",
    "print(model4.coef_)\n",
    "print(model4.intercept_)\n",
    "plt.scatter(X,y)\n",
    "y_hat = model4.predict(X)\n",
    "plt.plot(X,y_hat)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}